var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
var imgUrl = globalData.imgUrl;
Page({

  data: {
    imgUrl: imgUrl,
    info:[],
  },
  //加载已绑定银行卡
  loadDate:function(){
    let that = this;
    var params = new Object();
    params.page = 0;
    params.rows = 1;
    let openId = wx.getStorageSync("openidKey");
    commonUtil.showLoading("请稍等...");
    wx.request({
      url: httpsUrl + "/customerbankcard/list",
      header: { "openId": openId, "content-Type": "application/x-www-form-urlencoded" },
      dataType: "json",
      method: "GET",
      data: that.data.params,
      success: function (res) {
        commonUtil.hideLoading();
        console.log("已绑定银行卡：" + JSON.stringify(res));
        res = res.data;
        if (res.code == 0) {
          let rows = res.data;
          if (rows != null && rows != "" && rows.length >0){
            that.setData({ info:rows[0]})
          }
        }
      }
    })
  },

  //绑卡
  save: function (e) {
    var frm = e.detail.value;//form内容
    console.log("绑卡参数：" + JSON.stringify(frm));
    commonUtil.showLoading("请稍等...");
    let openId = wx.getStorageSync("openidKey");
    wx.request({
      header: { "openId": openId},
      url: httpsUrl + "/common/bankCardVerification",
      dataType: "json",
      method: "POST",
      data: frm,
      success: function (res) {
        commonUtil.hideLoading();
        console.log("绑卡返回：" + JSON.stringify(res));
        res = res.data;
        if (res.code == 0) {
          wx.navigateBack({
            delta:1
          })
        } else {
          commonUtil.showModal(res.message);
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadDate();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})